#!/bin/bash

####### A test script for the programs. #########

N_EXECS=5 		# number of times to execute each input
OUTPUTS=./outputs/mpi	# directory for outputs
SMOOTH_DEFAULT=5	# default K value
INPUTS=./inputs		# input directory
N_INPUTS=2		# number of inputs in input directory

printf '\n'
echo "Running script test for $N_INPUTS files in $INPUTS directory..."
printf '\n'

for ((i = 1; i <= $N_INPUTS; i++))
do 
	INPUT=input$i
	OUT=$OUTPUTS/$INPUT
	IN=$INPUTS/$INPUT

	mkdir $OUT

# running sequential
	echo "$INPUT >>>"
	echo "Running sequential program $N_EXECS times with SMOOTH_SQUARE_SIDE = 5..."
	for ((j = 1; j <= $N_EXECS; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/seq.times -a -f "%e" ./build/seq $IN $OUT/seq $SMOOTH_DEFAULT >> $OUT/seq.out
	done

# running for fixed SQUARE = 5
	printf '\n'
	echo "Running MPI program $N_EXECS times with SMOOTH_SQUARE_SIDE = 5..."

	for ((j = 1; j <= $N_EXECS; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/mpi.times -a -f "%e" mpirun -hostfile ./hosts -np 17 -npernode 1 ./build/mpi $IN $OUT/mpi >> $OUT/mpi.out
	done

# runnning test IO
	printf '\n'
	echo "Running test I/O"
	for ((j = 1; j <= 5; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/io_test.times -a -f "%e" ./build/io_test $IN $OUT/io_test_exit 
	done
	printf '\n'
done
